﻿using JamesZhao.Engine.Graphics.Surfaces;
using SlimDX;
using SlimDX.Direct3D11;
using SlimDX.DXGI;

namespace JamesZhao.Engine.Graphics.RenderStages
{
    internal class ClearStage : RenderStage
    {
        public Color4 ClearColor { get; set; }

        public ColorSurface[] Targets { get; set; }

        public override string Name
        {
            get { return "Clear"; }
        }

        protected override void OnRender(GraphicsDevice device, SwapChain swapChain, VisualsList visualsList,
                                         Camera camera)
        {
            device.ImmediateContext.ClearDepthStencilView(FinalDepthSurface.DepthView, DepthStencilClearFlags.Depth, 1,
                                                          0);
            device.ImmediateContext.ClearRenderTargetView(FinalColorSurface.TargetView, ClearColor);
            //todo: hack
            foreach (var target in Targets)
            {
                device.ImmediateContext.ClearRenderTargetView(target.TargetView, ClearColor);
            }
        }
    }
}